package com.css.fxfzaqbz.modules.estimate.repository.impl;

import com.css.fxfzaqbz.modules.estimate.entity.Fault;
import com.css.fxfzaqbz.modules.estimate.entity.StrongCatalog;
import com.css.fxfzaqbz.modules.estimate.repository.StrongCatalogRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class StrongCatalogRepositoryImpl implements StrongCatalogRepository {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
    //sys_strong_catalog
    @Override
    public void batchSave(List<StrongCatalog> list3) {
        SqlParameterSource[] beanSources = SqlParameterSourceUtils.createBatch(list3.toArray());
        String sql = "INSERT INTO sys_strong_catalog(jsc_id, province, city, district, town, event_id, event_abbrevia, occurrence_date, occurrence_time, location, longitude, latitude, magnitude, depth, epicenter, isoline, ilgraph_aiid, ilgraph_arwid, epic_intensity, accuracy, last_angle, comment_info, source_flag, del_flag, data_version, create_user, create_time, update_user, update_time, geom, extends1, extends2, extends3, extends4, extends5, extends6, extends7, extends8, extends9, extends10, result_analysis) values(:jscId, :province, :city, :district, :town, :eventId, :eventAbbrevia, :occurrenceDate, :occurrenceTime, :location, :longitude, :latitude, :magnitude, :depth, :epicenter, :isoline, :ilgraphAiid, :ilgraphArwid, :epicIntensity, :accuracy, :lastAngle, :commentInfo, :sourceFlag, :delFlag, :dataVersion, :createUser, :createTime, :updateUser, :updateTime, ST_GeometryFromText(:geom, 4490), :extends1, :extends2, :extends3, :extends4, :extends5, :extends6, :extends7, :extends8, :extends9, :extends10, :resultAnalysis)";
        namedParameterJdbcTemplate.batchUpdate(sql, beanSources);

    }

    @Override
    public List<StrongCatalog> getList(String resultAnalysis) {
        String sql = "select *,ST_AsText(geom) geom from sys_strong_catalog where result_analysis = '" + resultAnalysis + "'";
        List<StrongCatalog> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(StrongCatalog.class));
        return list;
    }
}
